package threads;

/**
 * @author apple
 * @Classname ThreadPriorityTask
 * @Description TODO
 * @Date 2020/4/19 17:59
 */
public class ThreadPriorityTask implements Runnable,Comparable<ThreadPriorityTask> {
    private int priority;
    private int count;

    public void setCount(int count) {
        this.count = count;
    }

    public int getPriority() {
        return priority;
    }

    public void setPriority(int priority) {
        this.priority = priority;
    }

    public ThreadPriorityTask(int priority){
        this.priority=priority;
    }
    /**

     */
    @Override
    public void run() {
        int sum = 0;
        for(int i=0;i<count;i++){
            sum += i;
        }
        System.out.println(Thread.currentThread()+"sum ="+sum);
        System.out.println(Thread.currentThread().getName());
        System.out.println(Thread.currentThread().getId());
    }

    /**

     */
    @Override
    public int compareTo(ThreadPriorityTask o) {
        return this.priority>o.priority?-1:1;
    }
}
